#include <iostream>

using namespace std;

#include <string>

#include "cppTutorThreadLib.h"

extern ThreadLib::Mutex m;

//ThreadLib::Mutex m;

void PrintThread (void *data)
{
    //SAU : Fix the below conversion
    // convert data inti character
    //char c = (char) data;
    char c = *(static_cast <char*> (data));
    for (int i = 0; i<50; i++)
    {
        m.Lock ();
        for (int j = 0; j<50; j++)
        {
            cout << c;
            cout.flush ();
        }
        m.Unlock ();
    }
}

int StartThread ()
{
    ThreadLib::ThreadID a, b;

    a = ThreadLib::Create (PrintThread, (void*)'a');
    b = ThreadLib::Create (PrintThread, (void*)'b');
    
    ThreadLib::WaitForFinish (b);
    ThreadLib::WaitForFinish (a);

    cin.ignore ();
    return 0;
}
